package com.bobo.serviceorder.service.impl;

import com.bobo.serviceorder.service.GrabService;
import com.bobo.serviceorder.service.OrderService;
import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author bobo
 * @date 2021-04-14
 */
@Service
public class GrabRedissonSentinelLockServiceImpl implements GrabService {

//    @Autowired
//    private Redisson redissonSentinel;

    @Autowired
    private OrderService orderService;

    @Override
    public String grabOrder(int orderId, int driverId) {
        String lockKey = "lock_" + orderId;
//        RLock lock = redissonSentinel.getLock(lockKey.intern());
//        lock.lock();
        boolean b = orderService.grabOrder(orderId, driverId);
        if (b) {
            System.out.println("枪单成功！-----sentinel");
        } else {
            System.out.println("枪单失败！------sentinel");
        }
//        lock.unlock();
        return b ? "枪单成功" : "枪单失败";
    }
}
